<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import editorDashboard from './editor'

export default {
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard },
  data() {
    return {
      currentRole: 'adminDashboard'
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    let admin = false

    if (this.roles) {
      for (let i = 0; i < this.roles.length; i++) {
        if (this.roles[i].code === 'admin') {
          admin = true
          break
        }
      }
    }

    if (admin) {
      this.currentRole = 'adminDashboard'
    } else {
      this.currentRole = 'editorDashboard'
      //  this.currentRole = 'editorDashboard'
    }
  }
}
</script>
